<?php

global $_W, $_GPC;
load()->func('tpl');
$op = empty($_GPC['op']) ? 'display' : $_GPC['op'];
if ($op == 'display') {
    $pindex = max(1, intval($_GPC['page']));
    $psize = 20;
    $order_info = pdo_fetchall('select o.*,m.nickname,m.avatar from ' . tablename('franchise_apply_order') . 'as o LEFT JOIN ' . tablename('franchise_apply_paylog') . "as p on o.ordersn  LEFT JOIN " . tablename('ewei_shop_member') . "as m on o.openid=m.openid where o.status>0 ORDER BY o.id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
    foreach ($order_info as $k => $v) {
        if ($v['shop_type'] == 1) {
            $order_info[$k]['shop_type'] = "美龄妈咪产后修复店中店";
        }
        if ($v['shop_type'] == 2) {
            $order_info[$k]['shop_type'] = "美龄范社区母婴店";
        }
        if ($v['shop_type'] == 3) {
            $order_info[$k]['shop_type'] = "AK系列产品";
        }
        if ($v['shop_type'] == 4) {
            $order_info[$k]['shop_type'] = "荷尔蒙系列";
        }
        $order_info[$k]['createtime'] = date('Y-m-d H-i-s', $v['createtime']);
        if ($v['sendtime'] > 0) {
            $order_info[$k]['sendtime'] = date('Y-m-d H-i-s', $v['sendtime']);
        } else {
            $order_info[$k]['sendtime'] = "";
        }
    }
    $total = pdo_fetchcolumn('select * from ' . tablename('franchise_apply_order') . 'as o LEFT JOIN ' . tablename('franchise_apply_paylog') . "as p on o.ordersn  LEFT JOIN " . tablename('ewei_shop_member') . "as m on o.openid=m.openid where o.status>0 ORDER BY o.id DESC ");
    $pager = pagination($total, $pindex, $psize);
    include $this->template('web/franchise/list');
    exit;
}
if($op == 'detail'){
    $orderid=intval($_GPC['order_id']);
    if(empty($orderid)){
       message('订单不存在!',$this->createWebUrl('franchise/list'), 'error');
    }
    $order_detail=pdo_fetch('select o.*,m.nickname,m.avatar from ' . tablename('franchise_apply_order') . 'as o LEFT JOIN ' . tablename('franchise_apply_paylog') . "as p on o.ordersn  LEFT JOIN " . tablename('ewei_shop_member') . "as m on o.openid=m.openid where o.status>0 and o.id=:id ORDER BY o.id DESC ",array(':id'=>$orderid));
    include $this->template('web/franchise/list');
    exit;
}
if($op=="open"){
    $orderid=intval($_GPC['order_id']);
    if(empty($orderid)){
       message('订单不存在!',$this->createWebUrl('franchise/list'), 'error');
    }
    pdo_update('franchise_apply_order',array('status'=>2,'sendtime'=>time()),array('uniacid'=>$_W['uniacid'],'id'=>$orderid));
    $info=pdo_fetch("select * from".tablename("franchise_apply_order")." where uniacid=:uniacid and id=:id ",array(':uniacid'=>$_W['uniacid'],':id'=>$orderid));
    $msg = array(
    'first' => array('value' => "小妖商城通知！", "color" => "#4a5077"),
    'remark' => array('value' => "恭喜您成为我们的加盟伙伴，欢迎加入小妖大家庭\r\n进入【个人中心】，点击【加盟中心】，此为您专属功能，可以需求小妖家提供支持等信息", "color" => "#4a5077"),
    'remark3' => array('value' => "了解更多，联系客服或添加微信号：lanxuevip2016，将有客服为您解答！", "color" => "#4a5077")
    );
    m('message')->sendCustomNotice($info['openid'], $msg);
    message('审核成功!',referer(), 'success');
}